package model

import (
	"tushare/model/mysql"
)

type UserCollect struct {
	Id         int64  `json:"id"`
	UserId     int64  `json:"user_id"`
	Name       string `json:"name"`
	Url        string `json:"url"`
	CreateTime string `json:"create_time"`
}

func UserCollectCreate(uc UserCollect) {
	mysql.DB.Table("user_collect").Create(&uc)
}

func UserCollectList(page, pageSize, userId int64) []UserCollect {
	page = page
	pageSize = pageSize
	offset := (page - 1) * pageSize
	uc := []UserCollect{}
	table := mysql.DB.Table("user_collect")
	table = table.Where("user_id = ?", userId)
	table = table.Order("create_time desc").Limit(pageSize).Offset(offset).Find(&uc)
	return uc
}

func UserCollectCount(userId int64) int64 {
	var count int64
	table := mysql.DB.Table("user_collect")
	table = table.Where("user_id = ?", userId)
	table = table.Count(&count)
	return count
}
